#ifndef _KEY_H_
#define _KEY_H_

#include "main.h"

extern unsigned char keyValue;
//=========================================================
//=========================================================
typedef struct KeyMsgDef{
  GPIO_TypeDef* GPIO;
	uint16_t Pin;
  unsigned char ValueS;
	unsigned char ValueL;
	unsigned char FlagS;
	unsigned char FlagL;
	unsigned long Time;
	unsigned long Long;
}KeyMsgDef;

extern struct KeyMsgDef KeyItem[];
//=========================================================
//=========================================================
enum KEY_VALUE{
  KEY_NONE = 0,
	KEY_FAIL ,
	KEY_ADD_S ,
	KEY_DEC_S ,
	KEY_SET_S ,
	KEY_CAN_S ,
	KEY_ADD_L ,
	KEY_DEC_L ,
	KEY_SET_L ,
	KEY_CAN_L ,
};

//=========================================================
//=========================================================
#define KEY_ADD_SHORT_PRESS()  Key_Pressed(KeyItem[0].ValueS,&KeyItem[0].FlagS)
#define KEY_ADD_LONG_PRESS()   Key_Pressed(KeyItem[0].ValueL,&KeyItem[0].FlagL)
#define KEY_ADD_PRESS()        (KEY_ADD_SHORT_PRESS() + KEY_ADD_LONG_PRESS())

#define KEY_DEC_SHORT_PRESS()  Key_Pressed(KeyItem[1].ValueS,&KeyItem[1].FlagS)
#define KEY_DEC_LONG_PRESS()   Key_Pressed(KeyItem[1].ValueL,&KeyItem[1].FlagL)
#define KEY_DEC_PRESS()        (KEY_DEC_SHORT_PRESS() + KEY_DEC_LONG_PRESS())

#define KEY_SET_SHORT_PRESS()  Key_Pressed(KeyItem[2].ValueS,&KeyItem[2].FlagS)
#define KEY_SET_LONG_PRESS()   Key_Pressed(KeyItem[2].ValueL,&KeyItem[2].FlagL)
#define KEY_SET_PRESS()        (KEY_SET_SHORT_PRESS() + KEY_SET_LONG_PRESS())

#define KEY_CAN_SHORT_PRESS()  Key_Pressed(KeyItem[3].ValueS,&KeyItem[3].FlagS)
#define KEY_CAN_LONG_PRESS()   Key_Pressed(KeyItem[3].ValueL,&KeyItem[3].FlagL)
#define KEY_CAN_PRESS()        (KEY_CAN_SHORT_PRESS() + KEY_CAN_LONG_PRESS())

//=========================================================
//=========================================================
void Key_Init(void);
void Key_Scan(void);
unsigned char Key_Pressed(unsigned char value,unsigned char *flag);

#endif
